<?php $this->headScript()->appendFile($this->js('plugins/jquery.selectboxes.js'))
->appendFile($this->js('plugins/jquery.form.js'))
->appendFile($this->js('plugins/jquery.alerts.js'));
$this->headLink()->appendStylesheet($this->js('css/jquery.alerts.css'))
->appendStylesheet($this->Css('table.css'));
?>
<script>
$(document).ready(function(){
	// 取年級課程
       function getSubject() {
         $("#append-area").hide();
        $.get('<?php echo $this->route("get-subject")?>',
                {grade: $("#select-grade").val()},
                function(data) {
                    $("#select-subject").html(data);
                });

    }
    // 年級改變時
    $("#select-grade").change(function(){
         $("#append-area").hide();
        getSubject();
         $("#data-area").html('');
         $("#saveBtn").attr('disabled','disabled');
    });

    $("#select-subject").change(function(){
        var sn = $(this).val();
        var grade = $("#select-grade").val();
        if ($("#only_semester").attr('checked')=='')
            var only_semester = 0;
        else
            var only_semester =1;
       $.get("<?php echo $this->route('get-copy-data')?>",{
           sn:sn,
           grade:grade,
           only_semester : only_semester
           },
           function(data){
    	   $("#data-area").html(data);
         });
       $("#saveBtn").attr('disabled','disabled');
     });

    $("#saveBtn").click(function(){
        var source = $("input[name='sel-sn']:checked").attr('id').substr(4);
        var target = $("#select-subject").val();
        $.post("<?php echo $this->route('save')?>",
        	{
    		source : source,
    		target : target
        	},
        	function(data) {
            	$("#select-grade").trigger('change');
            }
         );
      });

    getSubject();
});
</script>

<form>
<div id="select-area">
<select id="select-grade" name="select-grade">
<?php echo $this->ClassGradeOptions()?>
</select>
<select id="select-subject" name="select-subject">
</select>

<input type="button"  id="saveBtn" value="<?php echo $this->translate('copy data')?>"  disabled="disabled"/>
</div>

<div id="data-area">

</div>

</form>
